#import "MapSharePoiTableViewCell.h"
#import <Masonry/Masonry.h>

@interface MapSharePoiTableViewCell()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subtitleLabel;
@property (nonatomic, strong) UIImageView *selectedImageView;

@end

@implementation MapSharePoiTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.subtitleLabel];
    [self.contentView addSubview:self.selectedImageView];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(@10);
        make.top.equalTo(@10);
    }];
    
    [self.subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(@10);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
    }];
    
    [self.selectedImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-20);
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
}

- (void)configure:(PoiModel *)model {
    self.titleLabel.text = model.poi.name;
    self.subtitleLabel.text = model.poi.address;
    self.selectedImageView.hidden = !model.selected;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = [UIFont systemFontOfSize:18];
    }
    return _titleLabel;
}

- (UILabel *)subtitleLabel {
    if (!_subtitleLabel) {
        _subtitleLabel = [[UILabel alloc] init];
        _subtitleLabel.textColor = [UIColor grayColor];
        _subtitleLabel.font = [UIFont systemFontOfSize:14];
    }
    return _subtitleLabel;
}

- (UIImageView *)selectedImageView {
    if (!_selectedImageView) {
        _selectedImageView = [[UIImageView alloc] init];
//        _selectedImageView.image = [UIImage imageNamed:@"duigou"];
        NSString *strResourcesBundle = [[NSBundle mainBundle] pathForResource:@"DTKMapBundle" ofType:@"bundle"];
        NSString *strC = [[NSBundle bundleWithPath:strResourcesBundle] pathForResource:@"duigou" ofType:@"png"];
        UIImage *imgC = [UIImage imageWithContentsOfFile:strC];
        _selectedImageView.image = imgC;
    }
    return _selectedImageView;
}

@end
